package local.blueheart.data.springdatademo.util;

import local.blueheart.data.springdatademo.domain.system.AppUser;
import local.blueheart.data.springdatademo.security.AppUsrePrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class SecurityUtils {

    public static AppUser getUser() {
        UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        AppUsrePrincipal appUsrePrincipal = (AppUsrePrincipal) userDetails;
        return appUsrePrincipal.getUser();
    }

    public static Long getUserId() {
        return getUser().getId();
    }

}
